<!-- src/components/EditDialog.vue -->
<template>
  <el-dialog v-model="isVisible" title="编辑别名" width="30%">
    <el-form>
      <el-form-item label="别名">
        <el-input v-model="newAlias" placeholder="请输入新的别名"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="save">保存</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    alias: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      isVisible: this.visible, // 使用本地状态来控制可见性
      newAlias: this.alias
    };
  },
  watch: {
    visible(val) {
      this.isVisible = val;
    },
    isVisible(val) {
      this.$emit('update:visible', val);
    },
    alias(newVal) {
      this.newAlias = newVal;  // 当 props 更新时同步更新本地数据
    }
  },
  methods: {
    save() {
      this.$emit('save', this.newAlias);
      this.close();
    },
    close() {
      this.isVisible = false; // 关闭弹窗
    }
  }
}
</script>

<style scoped>
.dialog-footer {
  text-align: right;
}
</style>